package com.jbp.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jbp.dao.TopRoomsDao;
import com.jbp.model.TopRooms;
import com.jbp.utils.PageUtils;
import com.jbp.utils.Query;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class TopRoomsService extends ServiceImpl<TopRoomsDao, TopRooms> implements IService<TopRooms> {


    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<TopRooms> queryWrapper = new QueryWrapper<>();
        if (params.get("id") != null) {
            queryWrapper.like("id",params.get("id"));
        }
        if (params.get("roomId") != null) {
            queryWrapper.like("room_id",params.get("roomId"));
        }
        if (params.get("roomName") != null) {
            queryWrapper.like("room_name",params.get("roomName"));
        }
        if (params.get("proportion") != null) {
            queryWrapper.like("proportion",params.get("proportion"));
        }
        if (params.get("amount") != null) {
            queryWrapper.like("amount",params.get("amount"));
        }
        if (params.get("img") != null) {
            queryWrapper.like("img",params.get("img"));
        }
        if (params.get("createTime") != null) {
            queryWrapper.like("create_time",params.get("createTime"));
        }
        if (params.get("flag") != null) {
            queryWrapper.like("flag",params.get("flag"));
        }
        if (params.get("baseAmount") != null) {
            queryWrapper.like("base_amount",params.get("baseAmount"));
        }
        if (params.get("contributeAmount") != null) {
            queryWrapper.like("contribute_amount",params.get("contributeAmount"));
        }
        if (params.get("position") != null) {
            queryWrapper.like("position",params.get("position"));
        }
        if (params.get("schedule") != null) {
            queryWrapper.like("schedule",params.get("schedule"));
        }
        if (params.get("fromDate")!=null) {
            queryWrapper.ge("create_time", params.get("fromDate"));
        }
        if (params.get("toDate")!=null) {
            queryWrapper.le("DATE_FORMAT(create_time,   '%Y-%m-%d')", params.get("toDate"));
        }
        queryWrapper.orderByDesc("id");
        IPage<TopRooms> page = this.page(
            new Query<TopRooms>().getPage(params), queryWrapper
        );
        return new PageUtils(page);
    }
}